Okay, so in today's lesson we are going to be having a look at GIS and how to code them.
Okay.
Now we've actually already looked at GIS in the previous section.
We spent two lessons looking at them.
So I would highly recommend that if you're not confident with what you guys are awesome in their properties
to go back.
And we've watched that because we're not going to be talking about what these properties are.
Instead, we're going to be learning about how to code them.
Okay.
So.
And that we could code.
Okay.
So over in starter we're going to add in a screen guy.
Oh so add in a screen guy.
Let's add in a text button as well.
And just put this I know I shouldn't be dragging it, but I'm just going to put it over here.
Doesn't matter too much about the specifics.
We're just learning about coding it.
Okay.
And I'm going to add a local script inside of that screen guy.
Okay.
So to start off with I am going to reference the screen guy and the text button.
Okay.
So local screen guy is equal to script dot parent and local text button is equal to screen guy dot text
button.
Okay.
Now one important thing guys to start off with okay is the way you reference them.
Okay.
So obviously I use script or parents because it makes it makes more sense because it's just inside of
it like that.
But it's actually won't work.
If I referenced it using GameStar to Guy and I touched on it a bit, um, in the previous lessons on
guys.
But what happens is when the when you play the game, the everything in star guy gets duplicated and
moved over to player guy, and player guy is inside of players.
And I can show you this as an example.
If we go ahead and play the game and we go inside star Guy, go inside screen, click on the text button
and change its color.
It won't change on our screen.
This is because it's called star to Guy.
These are the starting values for the guys.
They get then duplicated over to each player.
So if there's 30 players, there's 30 local scripts and 30 different screen guys.
So for each player can have individual different guys.
Because remember if one player wants their inventory open, um, it wouldn't make sense for everyone
to have their inventory open.
That's not how it would work.
Okay.
Um, and but if we go into players, go under me.
Um, go into player G y you can see here we have our screen guy listed here with our text button which
has a property a white color.
And if we change it it then changes on our screen.
So what this means is when you're referencing, you cannot reference star Guy because when you are using
these ones in here, but they don't change the values, nothing happens.
If you change those.
The ones you are wanting to be changing are the ones inside of the player.
Okay.
Just make sure when you are doing this you are referencing using the script, not by get using GameStar.
Okay, you could reference it using Gameplayers, but it is just a whole lot easier just to do it.
This method.
Okay, um, now reference those two.
I'm also going to reference the player by saying game dot players dot local player because I'm in a
local script here.
Okay.
So um, you can already pretty much script your guys.
Okay.
Um, it's just a little bit about referencing that you need to be aware of, but you can basically script
them already.
You can change their properties.
Most majority of the properties and so on.
But there are a couple of properties that you cannot change.
And there is one event that I would like to show you as well.
So you already know most of it.
I'm just showing you a couple extra things so that you can properly code guys yourself.
Okay, so I have a look in the properties tab.
Okay.
Are there any properties here which you don't know how to change?
Okay.
Have a look.
And um, I'll pause a minute so you can maybe think which ones look a bit different.
Okay.
And hopefully you've spotted that position and size have four numbers.
Okay.
We know how to code three numbers and one number.
Um, it's a bit different to code for numbers.
Okay.
And again anchor point over here has two numbers.
So that's a bit different to code that as well.
Okay.
So they are the ones that we're not going to be able to code just yet with our previous knowledge.
I'm going to show you how to code them now.
Okay.
So these include different data types.
So remember how I said right at the start when I showed you eight the first eight data types.
And I said something like um, this will allow you to change 99 or 95% of properties.
This is the extra 1%, um, that you'll likely come across.
Okay.
Is these these two these new data types?
Okay.
So the first one I'm going to have a look at is anchor point.
So anchor point has two values an x and a y.
Okay so let's write our anchor point.
Let's write a screen guy dot.
Um yep.
Screen.
You got a text button.
Sorry.
Text button.
Dot anchor point okay.
Now, um, when we use a Vector3 value, we have three numbers that we can use.
Okay.
An x, a y, and a z.
So we'd actually be using something called vector two okay.
Because you're kind of ignoring the z value.
So instead of it being three numbers x y z, there are two numbers x and y.
So we just use vector two.
So let's write out vector two.
And it's the exact same as vector three.
It's just a two instead of a three.
And you skip out the z value.
Okay.
So nothing too overly different.
Dot new.
And let's type in here 0.5 comma 0.5 to anchor it in the middle.
Okay.
And that is your vector two value.
Hopefully not too difficult.
Okay.
That one's not really was not.
Actor three okay.
Um, the next one, though, is a bit different and that is position and size.
Now, you might think some people kind of think, well, there's four values.
So why don't we just use vector four?
Vector four doesn't exist.
The reason why it doesn't exist is vector two has an x and a y.
Vector three has an x, y, and z.
What's vector four going to have?
W x y z.
There's no fourth dimension in this case.
Instead, we still have an x and a y value.
But we have two different types of x y value.
We have an x scale, an x offset, a y scale, and a y offset.
So we don't have a fourth dimension in our game, but instead we have a two dimensions.
But they have two separate values between them.
So we don't use vector.
Any vector two.
Vector three vector four stuff okay.
Instead we use a whole new data type called udim.
So we would write down here text button dot size okay.
And we could either use Udim or Udim two depending on if there's just one dimension or two dimensions,
or whether you're just whether you're simply looking at the X or Y, or looking at both x and y.
We can look at both.
So you're going to use Udim two.
So we're going to say dot size is equal to Udim two.
And we're going to write dot new.
So it's the same kind of format.
Okay.
And inside here we write in for numbers um first being the x scale then the x offsets and the y scale
and then the y offset.
So let's say 0.2 comma zero comma 0.4 comma zero for example.
Okay.
And that's it.
So it's not too difficult.
Um I mean there's no it's not like completely new.
It's just a slight variation of stuff you already know.
Okay.
Um, so this is.
So when might you be able to use when might you want to use udim is if there's a Udim two, there has
to be a just a standard udim.
And that's when you specifically look at either the X or y scale at an offset.
Okay.
So you could do this by saying text button dot position for example, and then saying dot x haven't
shown you that before.
Um, but because I kind of wanted you to use vector threes instead of using it this method, but um,
you can instead just say position dot x, position dot y, position dot z and just make it equal to
one number.
Okay.
But I wanted to show you vector three because it's much shorter than setting the x, y and z equal to
stuff.
Okay.
So in this case we're just looking at the x which has one scale and one offset.
So we would just say udim dot new and we put in our scale and offset.
So let's say I'm just going to put zero zero because the x goes horizontally.
I want it to be right at the left of my screen here.
Okay.
And let's just play the game and see how our changes.
Reference the wrong things that won't actually change.
Yet we see here the time it is changed or have an error here.
X cannot be assigned to.
I done something wrong here.
We have a look.
Position.
Dot x x dimension, scale and offset of the M2.
Yep is equal to m.nu.
Let's try 0.1 comma zero then.
Should work.
Hmm.
Oh, no.
Got the same error again.
X cannot be assigned to.
Hmm.
So usually what that what that what that error means is that, um, you can't assign the property.
So some properties.
Strangely enough, you can't assign them values but only take their values, so I must.
I must have been wrong about that.
Okay, um, so I guess I'll show you that as an example of udim.
But the only time you'd use it is when you're referring to the position not actually updating it.
So you can use text button, dot position dot x, but you can't make it equal to something a bit strange,
I know, but it was just it was more so just me showing you that it exists, I guess.
But again, it's nowhere near commonly used as to is okay.
And for the final thing I would like to show you about GIS is a quick event called Mouse button, one
click and this event works for the button.
Okay, so we already know when you hover over it, it kind of darkens us.
And a little icon appears on your mouse so you can click it.
Okay.
Now this obviously is a button.
So we want to know when the player clicks it so we can do some stuff.
And that's where the mouse button one click event comes in okay.
So reference the text button and reference its event which is mouse button one click.
Now there's quite a few variations of this, but mouse button, one click fires when the mouse is fully,
fully left clicked the button.
So one one click means left click okay.
You've also got things like mouse enter, mouse leave, um one down.
So when you move your mouse down or when you click down but not necessarily bring it back up again,
um, to click which is right clicking and so on.
Okay.
There's a lot of different variations for clicks and stuff, but none of them are nowhere near as much
used as mouse button.
One click okay, but feel free to try them out yourself, as it'd be really good if you could try out
some other variations of it.
Just so you are aware.
Okay, mouse button one click works just like any other event colon connect function.
Hopefully you've done that enough times now for it to be just memory at this point.
And when that text button is pressed, you can do whatever you'd like.
Okay, I'm going to show you just a quick example about how you might want to bring up a frame when
that happens as a very common thing to do when a player presses the button is to open up another object.
Okay, let's add in a frame and let's position it throughout the screen.
So anchor point 0.5, comma 0.5 and size one comma zero.
Comma one comma zero.
Um, some.
Position and its position in the middle one and zero comma 0.5 comma zero.
There we go.
Okay.
And the text button is now hidden.
So let's change the z index to two.
So it's in front of it.
And I'm also going to just change a different color of it to red.
So we can very easily see it.
And let's um.
Change the text color.
Two.
White.
Okay, cool.
Doesn't look the best I know, but it is what it is.
It's fine just for examples.
Okay.
Um, so we want the frame to be, um, visible off to start off with.
Okay.
And when they press the button, we want this button to work so that the frame opens and closes.
Okay.
So we don't just say that visible is equal to true, because otherwise you wouldn't be able to hide
it again.
So basically we check if it is visible already.
So all we need to reference it first.
So local frame is equal to screen guy.
So screen guy dot frame okay.
So check to see if it's visible.
If statement okay.
If frame dot visible.
So if the frame is visible that means when we click the button we want to hide it.
So if it's currently visible we want to make it invisible.
So frame dot visible is equal to false.
So basically we basically do the opposite of what the property currently is.
And we could do another if statement to check the opposite.
Or we again we could just write an else instead to say frame dot visible is equal to true.
Because if it's not true currently, that means it's false because booleans can only ever be one or
to be.
Okay, okay.
And let's quickly try this out.
Give it a minute.
There we go.
And let's left click.
Oops, sorry.
I should have noted that bit out because it's ever it didn't like it doesn't want to read past that.
Okay, which probably why it took so long.
Maybe, um.
Okay.
It's quite large now, but let's let's click it opens up the frame and circle it again and it removes
the frame.
Okay.
So there you go.
That's how um, GUI buttons work.
Okay.
One more quick thing is you can see that the guy doesn't cover the top bit.
Okay?
Sometimes you want that to happen, other times you don't.
So very simple fix go into your screen guy and turn ignore guy now set to be on.
Which basically means it ignores the top bit the top bar of your game.
Okay.
And that's it for guys okay.
So now we're applying our knowledge into different areas.
It's even more important that you try out some of these things yourself okay.
As you know all the knowledge already.
It's just some different examples in some unfamiliar cases okay.
So have some examples and try some things out with that and then join me in the next lesson after.